﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson2__练习题
{
    internal class Program
    {
        static void Main(string[] args)
        {

            #region 一:请简述栈的存储规则
            //先进后出的存储规则
            #endregion


            #region   利用存储结构Stack写一个方法实现二进制的计算
          
            Calc(10);
            Calc(20);
            Calc(16);
            #endregion
        }
        static void Calc(uint num)  
        {
          
            Console.Write("{0}的二进制是:",num);
            Stack stack = new Stack();
            while (true)   //逻辑执行压栈操作
            {
               

                if(num ==1)
                {
                    stack.Push(num);
                    break;
                }
                else
                {
                    stack.Push(num % 2); 

                }
                    num = num / 2;
            }
            while(stack.Count > 0)
            {
                for(int i = 0; i < stack.Count; i++)
                {
                    Console.Write(stack.Pop() + " ");  //出栈操作  后进先出的操作
                }
                   
            }
            Console.WriteLine("              ");
        }
    }
}
